{% extends "admin/admin_layout.html" %}
{% block admin_title %}权限用户列表{% endblock %}
{% block admin_head %}
<script type="text/javascript" src="/static/js/JsUser.js"></script>
{% endblock %}
{% set perm = request.perm_const %}
{% block admin_content %}
{% set perm = request.perm_const %}
<div class="sect">
    <form action="." method="post" onsubmit="if($('s_nick').value==''){new MsgBox({message:'还未输入用户昵称'});return false;}">
	<h2>权限用户列表
    	<span class="sub">共{{ page.paginator.count }}个用户</span>
        <span class="extra">
            <label>查找用户昵称：</label>
            <input type="text" id="s_nick" name="s_nick"  />
            <input type="submit" class="button btns" value="搜索" />
        </span>
    </h2>
    </form>
    <div class="sectContent">
    	<table id="auth_user_table" class="gTable">
        	<tr>
                <th class="m4">ID</th>
                <th class="m0">用户</th>
                <th class="m8">角色</th>
                <th class="m6">操作</th>
            </tr>
            {% for obj in page.object_list %}
            <tr{% if loop.index % 2 == 0 %} class="odd"{% endif %}>
                <td class="m4">{{ obj.id }}</td>
                <td>
                    <a href="/user/{{ obj.id }}/">{{ obj.nick_name }}</a>
                    (<span class="hint">{{ "%s  %s"|format(obj.name, request.utils.getGenderArea(obj,False)) }}</span>)<br />
                </td>
                <td class="m8">{% set rls = obj.getRoles() %}{% for rl in rls %}{{ rl.name }}&nbsp;{% endfor %}</td>
                <td class="m6">
                	{% if perm.check_perm_op(perm.perm_role,perm.op_change) %}
                	<a href="javascript:;"
                    	onclick="$('chg_user_id').value='{{ obj.id }}';$('chg_role_div').fshow({event:event});">更改</a>
                    {% endif %}
                	{% if perm.check_perm_op(perm.perm_user,perm.op_change) %}
                	<a href="javascript:;" onclick="rm_auth_user('{{ obj.id }}');">降职</a>
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </table>
        {% include "paginator.html" %}
        <input type="hidden" id="chg_user_id" />
    </div>
</div>
{% endblock %}
{% block popup_content %}
    <div id="chg_role_div" class="popup" style="display:none;">
    	<div class="sect">
        	<h2>
            	<span id="chg_role_title" class="title">改变角色</span>
                <span class="extra" onclick="$('chg_role_div').tHide();">关闭</span>
            </h2>
            <div class="sectContent gForm">
            	<div class="row">
                	<label>更改为：</label>
                    <select id="chg_role_input">
                    	{% for role in roles %}
                        	<option value="{{ role.id }}">{{ role.name }}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="sectBtn">
                	<input type="button" class="button" value="确定" onclick="change_role('chg_user_id','chg_role_input');" />
                    <a href="javascript:;" onclick="$('chg_role_div').tHide();">取消</a>
                </div>
            </div>
        </div>
    </div>
<script type="text/javascript">
function rm_auth_user(user_id){
    if (!confirm("你确定要删除选中用户的权限吗？"))return;
    var params = "user_id=" + user_id;
    new echoAjax({url:"/admin/user/rm_auth/", params:params,reLoad:true}).fire();
}
function change_role(user_id_input, role_id_input){
    var user_id = $(user_id_input).value;var role_id = $(role_id_input).value;
    if (!user_id) {new MsgBox({message:"未获取到用户"});return;}
    if (!role_id) {new MsgBox({message:"你未选定角色"});return;}
    var params = "role_id=" + role_id + "&user_id=" + user_id;
    new echoAjax({url:"/admin/user/chg_role/", params:params,reLoad:true}).fire();
}
</script>
{% endblock %}
